package com.banmoon.flyweight;

import java.util.HashMap;
import java.util.Map;

public class ChessPiecesFactory {

    private Map<String, ChessPieces> chessPiecesContainer = new HashMap<>();

    public ChessPieces getChessPieces(String type){
        ChessPieces chessPieces = chessPiecesContainer.get(type);
        if(!chessPiecesContainer.containsKey(type)){
            if("white".equals(type)){
                chessPieces = new ChessPieces("白");
            }else if("black".equals(type)){
                chessPieces = new ChessPieces("黑");
            }
            chessPiecesContainer.put(type, chessPieces);
        }
        return chessPieces;
    }

}
